package UILayer;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import java.awt.Component;

import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JApplet;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;

import ControllerLayer.ProductCtr;

import javax.swing.JRadioButton;

import ControllerLayer.*;
import ModelLayer.*;

/**
 * @author Gruppe 2
 *
 */
@SuppressWarnings("serial")
public class ProductUI extends JFrame {

	
	private JPanel contentPane;
	private JTextField textField;
	
	private String[] description = { "Test 1", "Test 2", "Test..n"};
	private int count = 0;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ProductUI frame = new ProductUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ProductUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 269, 361);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textField = new JTextField();
		textField.setBounds(33, 37, 89, 20);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JButton btnFind = new JButton("Find");
		btnFind.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				selectSingleProduct();
			}

			private void selectSingleProduct() {
				// TODO Auto-generated method stub
				ProductCtr pCtr = new ProductCtr();
				Product p = new Product();
				int id = Integer.parseInt(textField.getText());
				;
				
				try {
					p = pCtr.selectSingleProduct(id);
					textField_8.setText(p.getName());
					textField_7.setText("Kr " + Double.toString(p.getPurchasePrice()));
					textField_6.setText("Kr " + Double.toString(p.getSalesPrice()));
					textField_5.setText("Kr " + Double.toString(p.getRentPrice()));
					textField_4.setText(p.getCountryOfOrigin());
					textField_2.setText(Integer.toString(p.getMinStock()));
					
					if(p instanceof GunReplica) {
						textField_1.setText("Gun");
					} else if(p instanceof Clothing) {
						textField_1.setText("Cloth");
					} else if(p instanceof Equipment) {
						textField_1.setText("Equip");
					} else {
						textField_1.setText("Unknown");
					}
					
					textField_3.setText(p.getSupplier().getName());
		

					
					
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			
			}
			
			private void getProductInstance() {
				
			}
			
		});
		btnFind.setBounds(132, 36, 68, 23);
		contentPane.add(btnFind);
		
		JLabel lblId = new JLabel("ID");
		lblId.setBounds(10, 40, 46, 14);
		contentPane.add(lblId);
		
		JLabel lblNavn = new JLabel("Navn");
		lblNavn.setBounds(10, 85, 46, 14);
		contentPane.add(lblNavn);
		
		JLabel lblKbspris = new JLabel("K\u00F8bspris");
		lblKbspris.setBounds(10, 110, 68, 14);
		contentPane.add(lblKbspris);
		
		JLabel lblSalgspris = new JLabel("Salgspris");
		lblSalgspris.setBounds(10, 135, 68, 14);
		contentPane.add(lblSalgspris);
		
		JLabel lblPrisleje = new JLabel("Prisleje");
		lblPrisleje.setBounds(10, 160, 46, 14);
		contentPane.add(lblPrisleje);
		
		JLabel lblLand = new JLabel("Land");
		lblLand.setBounds(10, 185, 46, 14);
		contentPane.add(lblLand);
		
		JLabel lblMinLager = new JLabel("Min. lager");
		lblMinLager.setBounds(10, 210, 68, 14);
		contentPane.add(lblMinLager);
		
		JLabel lblProdukttype = new JLabel("Produkttype");
		lblProdukttype.setBounds(10, 235, 89, 14);
		contentPane.add(lblProdukttype);
		
		JLabel lblLeverandr = new JLabel("Leverand\u00F8r");
		lblLeverandr.setBounds(9, 259, 69, 14);
		contentPane.add(lblLeverandr);
		
		textField_1 = new JTextField();
		textField_1.setBounds(131, 232, 109, 20);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		textField_2 = new JTextField();
		textField_2.setBounds(131, 207, 109, 20);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		textField_3 = new JTextField();
		textField_3.setBounds(131, 256, 109, 20);
		contentPane.add(textField_3);
		textField_3.setColumns(10);
		
		textField_4 = new JTextField();
		textField_4.setBounds(131, 182, 109, 20);
		contentPane.add(textField_4);
		textField_4.setColumns(10);
		
		textField_5 = new JTextField();
		textField_5.setBounds(131, 157, 109, 20);
		contentPane.add(textField_5);
		textField_5.setColumns(10);
		
		textField_6 = new JTextField();
		textField_6.setBounds(131, 132, 109, 20);
		contentPane.add(textField_6);
		textField_6.setColumns(10);
		
		textField_7 = new JTextField();
		textField_7.setBounds(131, 107, 109, 20);
		contentPane.add(textField_7);
		textField_7.setColumns(10);
		
		textField_8 = new JTextField();
		textField_8.setBounds(131, 82, 109, 20);
		contentPane.add(textField_8);
		textField_8.setColumns(10);
		
		JButton btnOpret = new JButton("Opret");
		btnOpret.setBounds(32, 287, 89, 23);
		contentPane.add(btnOpret);
		
		JButton btnSlet = new JButton("Slet");
		btnSlet.setBounds(131, 287, 89, 23);
		contentPane.add(btnSlet);
		
		JLabel lblFindOgellerOpret = new JLabel("Find, opret og slet produkter");
		lblFindOgellerOpret.setBounds(9, 11, 231, 14);
		contentPane.add(lblFindOgellerOpret);
		
		JLabel label = new JLabel("_________________________________");
		label.setBounds(9, 53, 231, 14);
		contentPane.add(label);

		
	}
}
